package com.fei.wechat.middlewar.service.impl.admin;

import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.fei.wechat.common.constant.EnumConstant.DeleteFlag;
import com.fei.wechat.common.model.vo.PagerVo;
import com.fei.wechat.common.util.ObjectUtils;
import com.fei.wechat.middlewar.api.admin.IUserService;
import com.fei.wechat.middlewar.dao.admin.IUserDao;
import com.fei.wechat.middlewar.mode.bo.admin.UserBo;
import com.fei.wechat.middlewar.mode.entity.admin.User;
import com.fei.wechat.middlewar.mode.vo.admin.UserVo;

/**
 * 描述: 后台管理用户业务接口实现层
 * 版权: Copyright (c) 2018 
 * 公司: 飞翔科技 
 * 作者: 张进飞 
 * 版本: 1.0 
 * 创建日期: 2018年3月18日 
 * 创建时间: 下午10:29:50
 */
public class UserServiceImpl implements IUserService
{
    
    private static final Logger LOGGER = LoggerFactory.getLogger(UserServiceImpl.class);
    
    @Autowired
    private IUserDao userDao;
    
    @Override
    public User queryUserByLoginName(String loginName)
    {
        User user = null;
        try
        {
            user = userDao.queryUserByLoginName(loginName);
        }
        catch (Exception e)
        {
            LOGGER.error("查询用户异常", e);
        }
        return user;
    }
    
    @Override
    public PagerVo<UserVo> queryUserVoPage(UserBo userBo) throws Exception
    {
        Map<String, Object> params = ObjectUtils.objectToMap(userBo);
        params.put("deleteFlag", DeleteFlag._1.getFalg());
        int count = this.userDao.countUserVo(params);
        PagerVo<UserVo> pager = new PagerVo<UserVo>(userBo.getCurrentPage(), userBo.getPageSize(), count);
        int start = pager.getStart();
        int size = pager.getSize();
        params.put("start", start);
        params.put("size", size);
        List<UserVo> list = this.userDao.queryUserVoPage(params);
        pager.setData(list);
        return pager;
    }
    
}
